
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Getting Started with the LLVM System &mdash; LLVM 3.7 documentation</title>
    
    <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '3.7',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
    <link rel="next" title="Getting Started with the LLVM System using Microsoft Visual Studio" href="GettingStartedVS.html" />
    <link rel="prev" title="llvm-readobj - LLVM Object Reader" href="CommandGuide/llvm-readobj.html" />
<style type="text/css">
  table.right { float: right; margin-left: 20px; }
  table.right td { border: 1px solid #ccc; }
</style>

  </head>
  <body role="document">
<div class="logo">
  <a href="index.html">
    <img src="_static/logo.png"
         alt="LLVM Logo" width="250" height="88"/></a>
</div>

    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="GettingStartedVS.html" title="Getting Started with the LLVM System using Microsoft Visual Studio"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="CommandGuide/llvm-readobj.html" title="llvm-readobj - LLVM Object Reader"
             accesskey="P">previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>
 
      </ul>
    </div>


    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <div class="section" id="getting-started-with-the-llvm-system">
<h1>Getting Started with the LLVM System<a class="headerlink" href="#getting-started-with-the-llvm-system" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#overview" id="id7">Overview</a></li>
<li><a class="reference internal" href="#getting-started-quickly-a-summary" id="id8">Getting Started Quickly (A Summary)</a></li>
<li><a class="reference internal" href="#requirements" id="id9">Requirements</a><ul>
<li><a class="reference internal" href="#hardware" id="id10">Hardware</a></li>
<li><a class="reference internal" href="#software" id="id11">Software</a></li>
<li><a class="reference internal" href="#host-c-toolchain-both-compiler-and-standard-library" id="id12">Host C++ Toolchain, both Compiler and Standard Library</a><ul>
<li><a class="reference internal" href="#getting-a-modern-host-c-toolchain" id="id13">Getting a Modern Host C++ Toolchain</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#getting-started-with-llvm" id="id14">Getting Started with LLVM</a><ul>
<li><a class="reference internal" href="#terminology-and-notation" id="id15">Terminology and Notation</a></li>
<li><a class="reference internal" href="#setting-up-your-environment" id="id16">Setting Up Your Environment</a></li>
<li><a class="reference internal" href="#unpacking-the-llvm-archives" id="id17">Unpacking the LLVM Archives</a></li>
<li><a class="reference internal" href="#checkout-llvm-from-subversion" id="id18">Checkout LLVM from Subversion</a></li>
<li><a class="reference internal" href="#git-mirror" id="id19">Git Mirror</a><ul>
<li><a class="reference internal" href="#sending-patches-with-git" id="id20">Sending patches with Git</a></li>
<li><a class="reference internal" href="#for-developers-to-work-with-git-svn" id="id21">For developers to work with git-svn</a></li>
</ul>
</li>
<li><a class="reference internal" href="#local-llvm-configuration" id="id22">Local LLVM Configuration</a></li>
<li><a class="reference internal" href="#compiling-the-llvm-suite-source-code" id="id23">Compiling the LLVM Suite Source Code</a></li>
<li><a class="reference internal" href="#cross-compiling-llvm" id="id24">Cross-Compiling LLVM</a></li>
<li><a class="reference internal" href="#the-location-of-llvm-object-files" id="id25">The Location of LLVM Object Files</a></li>
<li><a class="reference internal" href="#optional-configuration-items" id="id26">Optional Configuration Items</a></li>
</ul>
</li>
<li><a class="reference internal" href="#general-layout" id="id27">Program Layout</a><ul>
<li><a class="reference internal" href="#llvm-examples" id="id28"><code class="docutils literal"><span class="pre">llvm/examples</span></code></a></li>
<li><a class="reference internal" href="#llvm-include" id="id29"><code class="docutils literal"><span class="pre">llvm/include</span></code></a></li>
<li><a class="reference internal" href="#llvm-lib" id="id30"><code class="docutils literal"><span class="pre">llvm/lib</span></code></a></li>
<li><a class="reference internal" href="#llvm-projects" id="id31"><code class="docutils literal"><span class="pre">llvm/projects</span></code></a></li>
<li><a class="reference internal" href="#llvm-runtime" id="id32"><code class="docutils literal"><span class="pre">llvm/runtime</span></code></a></li>
<li><a class="reference internal" href="#llvm-test" id="id33"><code class="docutils literal"><span class="pre">llvm/test</span></code></a></li>
<li><a class="reference internal" href="#test-suite" id="id34"><code class="docutils literal"><span class="pre">test-suite</span></code></a></li>
<li><a class="reference internal" href="#llvm-tools" id="id35"><code class="docutils literal"><span class="pre">llvm/tools</span></code></a></li>
<li><a class="reference internal" href="#llvm-utils" id="id36"><code class="docutils literal"><span class="pre">llvm/utils</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#an-example-using-the-llvm-tool-chain" id="id37">An Example Using the LLVM Tool Chain</a><ul>
<li><a class="reference internal" href="#example-with-clang" id="id38">Example with clang</a></li>
</ul>
</li>
<li><a class="reference internal" href="#common-problems" id="id39">Common Problems</a></li>
<li><a class="reference internal" href="#links" id="id40">Links</a></li>
</ul>
</div>
<div class="section" id="overview">
<h2><a class="toc-backref" href="#id7">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>Welcome to LLVM! In order to get started, you first need to know some basic
information.</p>
<p>First, LLVM comes in three pieces. The first piece is the LLVM suite. This
contains all of the tools, libraries, and header files needed to use LLVM.  It
contains an assembler, disassembler, bitcode analyzer and bitcode optimizer.  It
also contains basic regression tests that can be used to test the LLVM tools and
the Clang front end.</p>
<p>The second piece is the <a class="reference external" href="http://clang.llvm.org/">Clang</a> front end.  This
component compiles C, C++, Objective C, and Objective C++ code into LLVM
bitcode. Once compiled into LLVM bitcode, a program can be manipulated with the
LLVM tools from the LLVM suite.</p>
<p>There is a third, optional piece called Test Suite.  It is a suite of programs
with a testing harness that can be used to further test LLVM&#8217;s functionality
and performance.</p>
</div>
<div class="section" id="getting-started-quickly-a-summary">
<h2><a class="toc-backref" href="#id8">Getting Started Quickly (A Summary)</a><a class="headerlink" href="#getting-started-quickly-a-summary" title="Permalink to this headline">¶</a></h2>
<p>The LLVM Getting Started documentation may be out of date.  So, the <a class="reference external" href="http://clang.llvm.org/get_started.html">Clang
Getting Started</a> page might also be a
good place to start.</p>
<p>Here&#8217;s the short story for getting up and running quickly with LLVM:</p>
<ol class="arabic">
<li><p class="first">Read the documentation.</p>
</li>
<li><p class="first">Read the documentation.</p>
</li>
<li><p class="first">Remember that you were warned twice about reading the documentation.</p>
</li>
<li><p class="first">Checkout LLVM:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">where-you-want-llvm-to-live</span></code></li>
<li><code class="docutils literal"><span class="pre">svn</span> <span class="pre">co</span> <span class="pre">http://llvm.org/svn/llvm-project/llvm/trunk</span> <span class="pre">llvm</span></code></li>
</ul>
</li>
<li><p class="first">Checkout Clang:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">where-you-want-llvm-to-live</span></code></li>
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">llvm/tools</span></code></li>
<li><code class="docutils literal"><span class="pre">svn</span> <span class="pre">co</span> <span class="pre">http://llvm.org/svn/llvm-project/cfe/trunk</span> <span class="pre">clang</span></code></li>
</ul>
</li>
<li><p class="first">Checkout Compiler-RT:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">where-you-want-llvm-to-live</span></code></li>
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">llvm/projects</span></code></li>
<li><code class="docutils literal"><span class="pre">svn</span> <span class="pre">co</span> <span class="pre">http://llvm.org/svn/llvm-project/compiler-rt/trunk</span> <span class="pre">compiler-rt</span></code></li>
</ul>
</li>
<li><p class="first">Get the Test Suite Source Code <strong>[Optional]</strong></p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">where-you-want-llvm-to-live</span></code></li>
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">llvm/projects</span></code></li>
<li><code class="docutils literal"><span class="pre">svn</span> <span class="pre">co</span> <span class="pre">http://llvm.org/svn/llvm-project/test-suite/trunk</span> <span class="pre">test-suite</span></code></li>
</ul>
</li>
<li><p class="first">Configure and build LLVM and Clang:</p>
<p>The usual build uses <a class="reference external" href="CMake.html">CMake</a>. If you would rather use
autotools, see <a class="reference external" href="BuildingLLVMWithAutotools.html">Building LLVM with autotools</a>.</p>
<ul>
<li><p class="first"><code class="docutils literal"><span class="pre">cd</span> <span class="pre">where</span> <span class="pre">you</span> <span class="pre">want</span> <span class="pre">to</span> <span class="pre">build</span> <span class="pre">llvm</span></code></p>
</li>
<li><p class="first"><code class="docutils literal"><span class="pre">mkdir</span> <span class="pre">build</span></code></p>
</li>
<li><p class="first"><code class="docutils literal"><span class="pre">cd</span> <span class="pre">build</span></code></p>
</li>
<li><p class="first"><code class="docutils literal"><span class="pre">cmake</span> <span class="pre">-G</span> <span class="pre">&lt;generator&gt;</span> <span class="pre">[options]</span> <span class="pre">&lt;path</span> <span class="pre">to</span> <span class="pre">llvm</span> <span class="pre">sources&gt;</span></code></p>
<p>Some common generators are:</p>
<ul>
<li><p class="first"><code class="docutils literal"><span class="pre">Unix</span> <span class="pre">Makefiles</span></code> &#8212; for generating make-compatible parallel makefiles.</p>
</li>
<li><dl class="first docutils">
<dt><code class="docutils literal"><span class="pre">Ninja</span></code> &#8212; for generating <cite>Ninja &lt;http://martine.github.io/ninja/&gt;</cite></dt>
<dd><p class="first last">build files.</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><code class="docutils literal"><span class="pre">Visual</span> <span class="pre">Studio</span></code> &#8212; for generating Visual Studio projects and</dt>
<dd><p class="first last">solutions.</p>
</dd>
</dl>
</li>
<li><p class="first"><code class="docutils literal"><span class="pre">Xcode</span></code> &#8212; for generating Xcode projects.</p>
</li>
</ul>
<p>Some Common options:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">-DCMAKE_INSTALL_PREFIX=directory</span></code> &#8212; Specify for <em>directory</em> the full
pathname of where you want the LLVM tools and libraries to be installed
(default <code class="docutils literal"><span class="pre">/usr/local</span></code>).</li>
<li><code class="docutils literal"><span class="pre">-DCMAKE_BUILD_TYPE=type</span></code> &#8212; Valid options for <em>type</em> are Debug,
Release, RelWithDebInfo, and MinSizeRel. Default is Debug.</li>
<li><code class="docutils literal"><span class="pre">-DLLVM_ENABLE_ASSERTIONS=On</span></code> &#8212; Compile with assertion checks enabled
(default is Yes for Debug builds, No for all other build types).</li>
</ul>
</li>
<li><p class="first">Run your build tool of choice!</p>
<ul class="simple">
<li>The default target (i.e. <code class="docutils literal"><span class="pre">make</span></code>) will build all of LLVM</li>
<li>The <code class="docutils literal"><span class="pre">check-all</span></code> target (i.e. <code class="docutils literal"><span class="pre">make</span> <span class="pre">check-all</span></code>) will run the
regression tests to ensure everything is in working order.</li>
<li>CMake will generate build targets for each tool and library, and most
LLVM sub-projects generate their own <code class="docutils literal"><span class="pre">check-&lt;project&gt;</span></code> target.</li>
</ul>
</li>
<li><p class="first">For more information see <a class="reference external" href="CMake.html">CMake</a></p>
</li>
<li><p class="first">If you get an &#8220;internal compiler error (ICE)&#8221; or test failures, see
<a class="reference internal" href="#below">below</a>.</p>
</li>
</ul>
</li>
</ol>
<p>Consult the <a class="reference internal" href="#getting-started-with-llvm">Getting Started with LLVM</a> section for detailed information on
configuring and compiling LLVM.  See <a class="reference internal" href="#setting-up-your-environment">Setting Up Your Environment</a> for tips
that simplify working with the Clang front end and LLVM tools.  Go to <a class="reference internal" href="#program-layout">Program
Layout</a> to learn about the layout of the source code tree.</p>
</div>
<div class="section" id="requirements">
<h2><a class="toc-backref" href="#id9">Requirements</a><a class="headerlink" href="#requirements" title="Permalink to this headline">¶</a></h2>
<p>Before you begin to use the LLVM system, review the requirements given below.
This may save you some trouble by knowing ahead of time what hardware and
software you will need.</p>
<div class="section" id="hardware">
<h3><a class="toc-backref" href="#id10">Hardware</a><a class="headerlink" href="#hardware" title="Permalink to this headline">¶</a></h3>
<p>LLVM is known to work on the following host platforms:</p>
<table border="1" class="docutils">
<colgroup>
<col width="35%" />
<col width="40%" />
<col width="25%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">OS</th>
<th class="head">Arch</th>
<th class="head">Compilers</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>Linux</td>
<td>x86<sup>1</sup></td>
<td>GCC, Clang</td>
</tr>
<tr class="row-odd"><td>Linux</td>
<td>amd64</td>
<td>GCC, Clang</td>
</tr>
<tr class="row-even"><td>Linux</td>
<td>ARM<sup>4</sup></td>
<td>GCC, Clang</td>
</tr>
<tr class="row-odd"><td>Linux</td>
<td>PowerPC</td>
<td>GCC, Clang</td>
</tr>
<tr class="row-even"><td>Solaris</td>
<td>V9 (Ultrasparc)</td>
<td>GCC</td>
</tr>
<tr class="row-odd"><td>FreeBSD</td>
<td>x86<sup>1</sup></td>
<td>GCC, Clang</td>
</tr>
<tr class="row-even"><td>FreeBSD</td>
<td>amd64</td>
<td>GCC, Clang</td>
</tr>
<tr class="row-odd"><td>MacOS X<sup>2</sup></td>
<td>PowerPC</td>
<td>GCC</td>
</tr>
<tr class="row-even"><td>MacOS X</td>
<td>x86</td>
<td>GCC, Clang</td>
</tr>
<tr class="row-odd"><td>Cygwin/Win32</td>
<td>x86<sup>1, 3</sup></td>
<td>GCC</td>
</tr>
<tr class="row-even"><td>Windows</td>
<td>x86<sup>1</sup></td>
<td>Visual Studio</td>
</tr>
<tr class="row-odd"><td>Windows x64</td>
<td>x86-64</td>
<td>Visual Studio</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<ol class="last arabic simple">
<li>Code generation supported for Pentium processors and up</li>
<li>Code generation supported for 32-bit ABI only</li>
<li>To use LLVM modules on Win32-based system, you may configure LLVM
with <code class="docutils literal"><span class="pre">-DBUILD_SHARED_LIBS=On</span></code> for CMake builds or <code class="docutils literal"><span class="pre">--enable-shared</span></code>
for configure builds.</li>
<li>MCJIT not working well pre-v7, old JIT engine not supported any more.</li>
</ol>
</div>
<p>Note that you will need about 1-3 GB of space for a full LLVM build in Debug
mode, depending on the system (it is so large because of all the debugging
information and the fact that the libraries are statically linked into multiple
tools).  If you do not need many of the tools and you are space-conscious, you
can pass <code class="docutils literal"><span class="pre">ONLY_TOOLS=&quot;tools</span> <span class="pre">you</span> <span class="pre">need&quot;</span></code> to make.  The Release build requires
considerably less space.</p>
<p>The LLVM suite <em>may</em> compile on other platforms, but it is not guaranteed to do
so.  If compilation is successful, the LLVM utilities should be able to
assemble, disassemble, analyze, and optimize LLVM bitcode.  Code generation
should work as well, although the generated native code may not work on your
platform.</p>
</div>
<div class="section" id="software">
<h3><a class="toc-backref" href="#id11">Software</a><a class="headerlink" href="#software" title="Permalink to this headline">¶</a></h3>
<p>Compiling LLVM requires that you have several software packages installed. The
table below lists those required packages. The Package column is the usual name
for the software package that LLVM depends on. The Version column provides
&#8220;known to work&#8221; versions of the package. The Notes column describes how LLVM
uses the package and provides other details.</p>
<table border="1" class="docutils">
<colgroup>
<col width="52%" />
<col width="11%" />
<col width="38%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Package</th>
<th class="head">Version</th>
<th class="head">Notes</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><a class="reference external" href="http://savannah.gnu.org/projects/make">GNU Make</a></td>
<td>3.79, 3.79.1</td>
<td>Makefile/build processor</td>
</tr>
<tr class="row-odd"><td><a class="reference external" href="http://gcc.gnu.org/">GCC</a></td>
<td>&gt;=4.7.0</td>
<td>C/C++ compiler<sup>1</sup></td>
</tr>
<tr class="row-even"><td><a class="reference external" href="http://www.python.org/">python</a></td>
<td>&gt;=2.7</td>
<td>Automated test suite<sup>2</sup></td>
</tr>
<tr class="row-odd"><td><a class="reference external" href="http://savannah.gnu.org/projects/m4">GNU M4</a></td>
<td>1.4</td>
<td>Macro processor for configuration<sup>3</sup></td>
</tr>
<tr class="row-even"><td><a class="reference external" href="http://www.gnu.org/software/autoconf/">GNU Autoconf</a></td>
<td>2.60</td>
<td>Configuration script builder<sup>3</sup></td>
</tr>
<tr class="row-odd"><td><a class="reference external" href="http://www.gnu.org/software/automake/">GNU Automake</a></td>
<td>1.9.6</td>
<td>aclocal macro generator<sup>3</sup></td>
</tr>
<tr class="row-even"><td><a class="reference external" href="http://savannah.gnu.org/projects/libtool">libtool</a></td>
<td>1.5.22</td>
<td>Shared library manager<sup>3</sup></td>
</tr>
<tr class="row-odd"><td><a class="reference external" href="http://zlib.net">zlib</a></td>
<td>&gt;=1.2.3.4</td>
<td>Compression library<sup>4</sup></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<ol class="last arabic simple">
<li>Only the C and C++ languages are needed so there&#8217;s no need to build the
other languages for LLVM&#8217;s purposes. See <cite>below</cite> for specific version
info.</li>
<li>Only needed if you want to run the automated test suite in the
<code class="docutils literal"><span class="pre">llvm/test</span></code> directory.</li>
<li>If you want to make changes to the configure scripts, you will need GNU
autoconf (2.60), and consequently, GNU M4 (version 1.4 or higher). You
will also need automake (1.9.6). We only use aclocal from that package.</li>
<li>Optional, adds compression / uncompression capabilities to selected LLVM
tools.</li>
</ol>
</div>
<p>Additionally, your compilation host is expected to have the usual plethora of
Unix utilities. Specifically:</p>
<ul class="simple">
<li><strong>ar</strong> &#8212; archive library builder</li>
<li><strong>bzip2</strong> &#8212; bzip2 command for distribution generation</li>
<li><strong>bunzip2</strong> &#8212; bunzip2 command for distribution checking</li>
<li><strong>chmod</strong> &#8212; change permissions on a file</li>
<li><strong>cat</strong> &#8212; output concatenation utility</li>
<li><strong>cp</strong> &#8212; copy files</li>
<li><strong>date</strong> &#8212; print the current date/time</li>
<li><strong>echo</strong> &#8212; print to standard output</li>
<li><strong>egrep</strong> &#8212; extended regular expression search utility</li>
<li><strong>find</strong> &#8212; find files/dirs in a file system</li>
<li><strong>grep</strong> &#8212; regular expression search utility</li>
<li><strong>gzip</strong> &#8212; gzip command for distribution generation</li>
<li><strong>gunzip</strong> &#8212; gunzip command for distribution checking</li>
<li><strong>install</strong> &#8212; install directories/files</li>
<li><strong>mkdir</strong> &#8212; create a directory</li>
<li><strong>mv</strong> &#8212; move (rename) files</li>
<li><strong>ranlib</strong> &#8212; symbol table builder for archive libraries</li>
<li><strong>rm</strong> &#8212; remove (delete) files and directories</li>
<li><strong>sed</strong> &#8212; stream editor for transforming output</li>
<li><strong>sh</strong> &#8212; Bourne shell for make build scripts</li>
<li><strong>tar</strong> &#8212; tape archive for distribution generation</li>
<li><strong>test</strong> &#8212; test things in file system</li>
<li><strong>unzip</strong> &#8212; unzip command for distribution checking</li>
<li><strong>zip</strong> &#8212; zip command for distribution generation</li>
</ul>
</div>
<div class="section" id="host-c-toolchain-both-compiler-and-standard-library">
<span id="check-here"></span><span id="below"></span><h3><a class="toc-backref" href="#id12">Host C++ Toolchain, both Compiler and Standard Library</a><a class="headerlink" href="#host-c-toolchain-both-compiler-and-standard-library" title="Permalink to this headline">¶</a></h3>
<p>LLVM is very demanding of the host C++ compiler, and as such tends to expose
bugs in the compiler. We are also planning to follow improvements and
developments in the C++ language and library reasonably closely. As such, we
require a modern host C++ toolchain, both compiler and standard library, in
order to build LLVM.</p>
<p>For the most popular host toolchains we check for specific minimum versions in
our build systems:</p>
<ul class="simple">
<li>Clang 3.1</li>
<li>GCC 4.7</li>
<li>Visual Studio 2013</li>
</ul>
<p>Anything older than these toolchains <em>may</em> work, but will require forcing the
build system with a special option and is not really a supported host platform.
Also note that older versions of these compilers have often crashed or
miscompiled LLVM.</p>
<p>For less widely used host toolchains such as ICC or xlC, be aware that a very
recent version may be required to support all of the C++ features used in LLVM.</p>
<p>We track certain versions of software that are <em>known</em> to fail when used as
part of the host toolchain. These even include linkers at times.</p>
<p><strong>GCC 4.6.3 on ARM</strong>: Miscompiles <code class="docutils literal"><span class="pre">llvm-readobj</span></code> at <code class="docutils literal"><span class="pre">-O3</span></code>. A test failure
in <code class="docutils literal"><span class="pre">test/Object/readobj-shared-object.test</span></code> is one symptom of the problem.</p>
<p><strong>GNU ld 2.16.X</strong>. Some 2.16.X versions of the ld linker will produce very long
warning messages complaining that some &#8220;<code class="docutils literal"><span class="pre">.gnu.linkonce.t.*</span></code>&#8221; symbol was
defined in a discarded section. You can safely ignore these messages as they are
erroneous and the linkage is correct.  These messages disappear using ld 2.17.</p>
<p><strong>GNU binutils 2.17</strong>: Binutils 2.17 contains <a class="reference external" href="http://sourceware.org/bugzilla/show_bug.cgi?id=3111">a bug</a> which causes huge link
times (minutes instead of seconds) when building LLVM.  We recommend upgrading
to a newer version (2.17.50.0.4 or later).</p>
<p><strong>GNU Binutils 2.19.1 Gold</strong>: This version of Gold contained <a class="reference external" href="http://sourceware.org/bugzilla/show_bug.cgi?id=9836">a bug</a> which causes
intermittent failures when building LLVM with position independent code.  The
symptom is an error about cyclic dependencies.  We recommend upgrading to a
newer version of Gold.</p>
<p><strong>Clang 3.0 with libstdc++ 4.7.x</strong>: a few Linux distributions (Ubuntu 12.10,
Fedora 17) have both Clang 3.0 and libstdc++ 4.7 in their repositories.  Clang
3.0 does not implement a few builtins that are used in this library.  We
recommend using the system GCC to compile LLVM and Clang in this case.</p>
<p><strong>Clang 3.0 on Mageia 2</strong>.  There&#8217;s a packaging issue: Clang can not find at
least some (<code class="docutils literal"><span class="pre">cxxabi.h</span></code>) libstdc++ headers.</p>
<p><strong>Clang in C++11 mode and libstdc++ 4.7.2</strong>.  This version of libstdc++
contained <a class="reference external" href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53841">a bug</a> which
causes Clang to refuse to compile condition_variable header file.  At the time
of writing, this breaks LLD build.</p>
<div class="section" id="getting-a-modern-host-c-toolchain">
<h4><a class="toc-backref" href="#id13">Getting a Modern Host C++ Toolchain</a><a class="headerlink" href="#getting-a-modern-host-c-toolchain" title="Permalink to this headline">¶</a></h4>
<p>This section mostly applies to Linux and older BSDs. On Mac OS X, you should
have a sufficiently modern Xcode, or you will likely need to upgrade until you
do. On Windows, just use Visual Studio 2013 as the host compiler, it is
explicitly supported and widely available. FreeBSD 10.0 and newer have a modern
Clang as the system compiler.</p>
<p>However, some Linux distributions and some other or older BSDs sometimes have
extremely old versions of GCC. These steps attempt to help you upgrade you
compiler even on such a system. However, if at all possible, we encourage you
to use a recent version of a distribution with a modern system compiler that
meets these requirements. Note that it is tempting to to install a prior
version of Clang and libc++ to be the host compiler, however libc++ was not
well tested or set up to build on Linux until relatively recently. As
a consequence, this guide suggests just using libstdc++ and a modern GCC as the
initial host in a bootstrap, and then using Clang (and potentially libc++).</p>
<p>The first step is to get a recent GCC toolchain installed. The most common
distribution on which users have struggled with the version requirements is
Ubuntu Precise, 12.04 LTS. For this distribution, one easy option is to install
the <a class="reference external" href="https://launchpad.net/~ubuntu-toolchain-r/+archive/test">toolchain testing PPA</a> and use it to install a modern GCC. There is
a really nice discussions of this on the <a class="reference external" href="http://askubuntu.com/questions/271388/how-to-install-gcc-4-8-in-ubuntu-12-04-from-the-terminal">ask ubuntu stack exchange</a>. However,
not all users can use PPAs and there are many other distributions, so it may be
necessary (or just useful, if you&#8217;re here you <em>are</em> doing compiler development
after all) to build and install GCC from source. It is also quite easy to do
these days.</p>
<p>Easy steps for installing GCC 4.8.2:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2
<span class="gp">%</span> wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2.sig
<span class="gp">%</span> wget https://ftp.gnu.org/gnu/gnu-keyring.gpg
<span class="gp">%</span> <span class="nv">signature_invalid</span><span class="o">=</span><span class="sb">`</span>gpg --verify --no-default-keyring --keyring ./gnu-keyring.gpg gcc-4.8.2.tar.bz2.sig<span class="sb">`</span>
<span class="gp">%</span> <span class="k">if</span> <span class="o">[</span> <span class="nv">$signature_invalid</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span> <span class="nb">echo</span> <span class="s2">&quot;Invalid signature&quot;</span> <span class="p">;</span> <span class="nb">exit </span><span class="m">1</span> <span class="p">;</span> <span class="k">fi</span>
<span class="gp">%</span> tar -xvjf gcc-4.8.2.tar.bz2
<span class="gp">%</span> <span class="nb">cd </span>gcc-4.8.2
<span class="gp">%</span> ./contrib/download_prerequisites
<span class="gp">%</span> <span class="nb">cd</span> ..
<span class="gp">%</span> mkdir gcc-4.8.2-build
<span class="gp">%</span> <span class="nb">cd </span>gcc-4.8.2-build
<span class="gp">%</span> <span class="nv">$PWD</span>/../gcc-4.8.2/configure --prefix<span class="o">=</span><span class="nv">$HOME</span>/toolchains --enable-languages<span class="o">=</span>c,c++
<span class="gp">%</span> make -j<span class="k">$(</span>nproc<span class="k">)</span>
<span class="gp">%</span> make install
</pre></div>
</div>
<p>For more details, check out the excellent <a class="reference external" href="http://gcc.gnu.org/wiki/InstallingGCC">GCC wiki entry</a>, where I got most
of this information from.</p>
<p>Once you have a GCC toolchain, configure your build of LLVM to use the new
toolchain for your host compiler and C++ standard library. Because the new
version of libstdc++ is not on the system library search path, you need to pass
extra linker flags so that it can be found at link time (<code class="docutils literal"><span class="pre">-L</span></code>) and at runtime
(<code class="docutils literal"><span class="pre">-rpath</span></code>). If you are using CMake, this invocation should produce working
binaries:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> mkdir build
<span class="gp">%</span> <span class="nb">cd </span>build
<span class="gp">%</span> <span class="nv">CC</span><span class="o">=</span><span class="nv">$HOME</span>/toolchains/bin/gcc <span class="nv">CXX</span><span class="o">=</span><span class="nv">$HOME</span>/toolchains/bin/g++ <span class="se">\</span>
<span class="go">  cmake .. -DCMAKE_CXX_LINK_FLAGS=&quot;-Wl,-rpath,$HOME/toolchains/lib64 -L$HOME/toolchains/lib64&quot;</span>
</pre></div>
</div>
<p>If you fail to set rpath, most LLVM binaries will fail on startup with a message
from the loader similar to <code class="docutils literal"><span class="pre">libstdc++.so.6:</span> <span class="pre">version</span> <span class="pre">`GLIBCXX_3.4.20'</span> <span class="pre">not</span>
<span class="pre">found</span></code>. This means you need to tweak the -rpath linker flag.</p>
<p>When you build Clang, you will need to give <em>it</em> access to modern C++11
standard library in order to use it as your new host in part of a bootstrap.
There are two easy ways to do this, either build (and install) libc++ along
with Clang and then use it with the <code class="docutils literal"><span class="pre">-stdlib=libc++</span></code> compile and link flag,
or install Clang into the same prefix (<code class="docutils literal"><span class="pre">$HOME/toolchains</span></code> above) as GCC.
Clang will look within its own prefix for libstdc++ and use it if found. You
can also add an explicit prefix for Clang to look in for a GCC toolchain with
the <code class="docutils literal"><span class="pre">--gcc-toolchain=/opt/my/gcc/prefix</span></code> flag, passing it to both compile and
link commands when using your just-built-Clang to bootstrap.</p>
</div>
</div>
</div>
<div class="section" id="getting-started-with-llvm">
<span id="id2"></span><h2><a class="toc-backref" href="#id14">Getting Started with LLVM</a><a class="headerlink" href="#getting-started-with-llvm" title="Permalink to this headline">¶</a></h2>
<p>The remainder of this guide is meant to get you up and running with LLVM and to
give you some basic information about the LLVM environment.</p>
<p>The later sections of this guide describe the <a class="reference internal" href="#general-layout">general layout</a> of the LLVM
source tree, a <a class="reference internal" href="#simple-example">simple example</a> using the LLVM tool chain, and <a class="reference internal" href="#links">links</a> to find
more information about LLVM or to get help via e-mail.</p>
<div class="section" id="terminology-and-notation">
<h3><a class="toc-backref" href="#id15">Terminology and Notation</a><a class="headerlink" href="#terminology-and-notation" title="Permalink to this headline">¶</a></h3>
<p>Throughout this manual, the following names are used to denote paths specific to
the local system and working environment.  <em>These are not environment variables
you need to set but just strings used in the rest of this document below</em>.  In
any of the examples below, simply replace each of these names with the
appropriate pathname on your local system.  All these paths are absolute:</p>
<p><code class="docutils literal"><span class="pre">SRC_ROOT</span></code></p>
<blockquote>
<div>This is the top level directory of the LLVM source tree.</div></blockquote>
<p><code class="docutils literal"><span class="pre">OBJ_ROOT</span></code></p>
<blockquote>
<div>This is the top level directory of the LLVM object tree (i.e. the tree where
object files and compiled programs will be placed.  It can be the same as
SRC_ROOT).</div></blockquote>
</div>
<div class="section" id="setting-up-your-environment">
<span id="id3"></span><h3><a class="toc-backref" href="#id16">Setting Up Your Environment</a><a class="headerlink" href="#setting-up-your-environment" title="Permalink to this headline">¶</a></h3>
<p>In order to compile and use LLVM, you may need to set some environment
variables.</p>
<p><code class="docutils literal"><span class="pre">LLVM_LIB_SEARCH_PATH=/path/to/your/bitcode/libs</span></code></p>
<blockquote>
<div>[Optional] This environment variable helps LLVM linking tools find the
locations of your bitcode libraries. It is provided only as a convenience
since you can specify the paths using the -L options of the tools and the
C/C++ front-end will automatically use the bitcode files installed in its
<code class="docutils literal"><span class="pre">lib</span></code> directory.</div></blockquote>
</div>
<div class="section" id="unpacking-the-llvm-archives">
<h3><a class="toc-backref" href="#id17">Unpacking the LLVM Archives</a><a class="headerlink" href="#unpacking-the-llvm-archives" title="Permalink to this headline">¶</a></h3>
<p>If you have the LLVM distribution, you will need to unpack it before you can
begin to compile it.  LLVM is distributed as a set of two files: the LLVM suite
and the LLVM GCC front end compiled for your platform.  There is an additional
test suite that is optional.  Each file is a TAR archive that is compressed with
the gzip program.</p>
<p>The files are as follows, with <em>x.y</em> marking the version number:</p>
<p><code class="docutils literal"><span class="pre">llvm-x.y.tar.gz</span></code></p>
<blockquote>
<div>Source release for the LLVM libraries and tools.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm-test-x.y.tar.gz</span></code></p>
<blockquote>
<div>Source release for the LLVM test-suite.</div></blockquote>
</div>
<div class="section" id="checkout-llvm-from-subversion">
<span id="checkout"></span><h3><a class="toc-backref" href="#id18">Checkout LLVM from Subversion</a><a class="headerlink" href="#checkout-llvm-from-subversion" title="Permalink to this headline">¶</a></h3>
<p>If you have access to our Subversion repository, you can get a fresh copy of the
entire source code.  All you need to do is check it out from Subversion as
follows:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">where-you-want-llvm-to-live</span></code></li>
<li>Read-Only: <code class="docutils literal"><span class="pre">svn</span> <span class="pre">co</span> <span class="pre">http://llvm.org/svn/llvm-project/llvm/trunk</span> <span class="pre">llvm</span></code></li>
<li>Read-Write: <code class="docutils literal"><span class="pre">svn</span> <span class="pre">co</span> <span class="pre">https://user&#64;llvm.org/svn/llvm-project/llvm/trunk</span> <span class="pre">llvm</span></code></li>
</ul>
<p>This will create an &#8216;<code class="docutils literal"><span class="pre">llvm</span></code>&#8216; directory in the current directory and fully
populate it with the LLVM source code, Makefiles, test directories, and local
copies of documentation files.</p>
<p>If you want to get a specific release (as opposed to the most recent revision),
you can checkout it from the &#8216;<code class="docutils literal"><span class="pre">tags</span></code>&#8216; directory (instead of &#8216;<code class="docutils literal"><span class="pre">trunk</span></code>&#8216;). The
following releases are located in the following subdirectories of the &#8216;<code class="docutils literal"><span class="pre">tags</span></code>&#8216;
directory:</p>
<ul class="simple">
<li>Release 3.4: <strong>RELEASE_34/final</strong></li>
<li>Release 3.3: <strong>RELEASE_33/final</strong></li>
<li>Release 3.2: <strong>RELEASE_32/final</strong></li>
<li>Release 3.1: <strong>RELEASE_31/final</strong></li>
<li>Release 3.0: <strong>RELEASE_30/final</strong></li>
<li>Release 2.9: <strong>RELEASE_29/final</strong></li>
<li>Release 2.8: <strong>RELEASE_28</strong></li>
<li>Release 2.7: <strong>RELEASE_27</strong></li>
<li>Release 2.6: <strong>RELEASE_26</strong></li>
<li>Release 2.5: <strong>RELEASE_25</strong></li>
<li>Release 2.4: <strong>RELEASE_24</strong></li>
<li>Release 2.3: <strong>RELEASE_23</strong></li>
<li>Release 2.2: <strong>RELEASE_22</strong></li>
<li>Release 2.1: <strong>RELEASE_21</strong></li>
<li>Release 2.0: <strong>RELEASE_20</strong></li>
<li>Release 1.9: <strong>RELEASE_19</strong></li>
<li>Release 1.8: <strong>RELEASE_18</strong></li>
<li>Release 1.7: <strong>RELEASE_17</strong></li>
<li>Release 1.6: <strong>RELEASE_16</strong></li>
<li>Release 1.5: <strong>RELEASE_15</strong></li>
<li>Release 1.4: <strong>RELEASE_14</strong></li>
<li>Release 1.3: <strong>RELEASE_13</strong></li>
<li>Release 1.2: <strong>RELEASE_12</strong></li>
<li>Release 1.1: <strong>RELEASE_11</strong></li>
<li>Release 1.0: <strong>RELEASE_1</strong></li>
</ul>
<p>If you would like to get the LLVM test suite (a separate package as of 1.4), you
get it from the Subversion repository:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>llvm/projects
<span class="gp">%</span> svn co http://llvm.org/svn/llvm-project/test-suite/trunk <span class="nb">test</span>-suite
</pre></div>
</div>
<p>By placing it in the <code class="docutils literal"><span class="pre">llvm/projects</span></code>, it will be automatically configured by
the LLVM configure script as well as automatically updated when you run <code class="docutils literal"><span class="pre">svn</span>
<span class="pre">update</span></code>.</p>
</div>
<div class="section" id="git-mirror">
<h3><a class="toc-backref" href="#id19">Git Mirror</a><a class="headerlink" href="#git-mirror" title="Permalink to this headline">¶</a></h3>
<p>Git mirrors are available for a number of LLVM subprojects. These mirrors sync
automatically with each Subversion commit and contain all necessary git-svn
marks (so, you can recreate git-svn metadata locally). Note that right now
mirrors reflect only <code class="docutils literal"><span class="pre">trunk</span></code> for each project. You can do the read-only Git
clone of LLVM via:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git clone http://llvm.org/git/llvm.git
</pre></div>
</div>
<p>If you want to check out clang too, run:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>llvm/tools
<span class="gp">%</span> git clone http://llvm.org/git/clang.git
</pre></div>
</div>
<p>If you want to check out compiler-rt too, run:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>llvm/projects
<span class="gp">%</span> git clone http://llvm.org/git/compiler-rt.git
</pre></div>
</div>
<p>If you want to check out the Test Suite Source Code (optional), run:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>llvm/projects
<span class="gp">%</span> git clone http://llvm.org/git/test-suite.git
</pre></div>
</div>
<p>Since the upstream repository is in Subversion, you should use <code class="docutils literal"><span class="pre">git</span>
<span class="pre">pull</span> <span class="pre">--rebase</span></code> instead of <code class="docutils literal"><span class="pre">git</span> <span class="pre">pull</span></code> to avoid generating a non-linear history
in your clone.  To configure <code class="docutils literal"><span class="pre">git</span> <span class="pre">pull</span></code> to pass <code class="docutils literal"><span class="pre">--rebase</span></code> by default on the
master branch, run the following command:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git config branch.master.rebase <span class="nb">true</span>
</pre></div>
</div>
<div class="section" id="sending-patches-with-git">
<h4><a class="toc-backref" href="#id20">Sending patches with Git</a><a class="headerlink" href="#sending-patches-with-git" title="Permalink to this headline">¶</a></h4>
<p>Please read <a class="reference external" href="DeveloperPolicy.html#one-off-patches">Developer Policy</a>, too.</p>
<p>Assume <code class="docutils literal"><span class="pre">master</span></code> points the upstream and <code class="docutils literal"><span class="pre">mybranch</span></code> points your working
branch, and <code class="docutils literal"><span class="pre">mybranch</span></code> is rebased onto <code class="docutils literal"><span class="pre">master</span></code>.  At first you may check
sanity of whitespaces:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git diff --check master..mybranch
</pre></div>
</div>
<p>The easiest way to generate a patch is as below:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git diff master..mybranch &gt; /path/to/mybranch.diff
</pre></div>
</div>
<p>It is a little different from svn-generated diff. git-diff-generated diff has
prefixes like <code class="docutils literal"><span class="pre">a/</span></code> and <code class="docutils literal"><span class="pre">b/</span></code>. Don&#8217;t worry, most developers might know it
could be accepted with <code class="docutils literal"><span class="pre">patch</span> <span class="pre">-p1</span> <span class="pre">-N</span></code>.</p>
<p>But you may generate patchset with git-format-patch. It generates by-each-commit
patchset. To generate patch files to attach to your article:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git format-patch --no-attach master..mybranch -o /path/to/your/patchset
</pre></div>
</div>
<p>If you would like to send patches directly, you may use git-send-email or
git-imap-send. Here is an example to generate the patchset in Gmail&#8217;s [Drafts].</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git format-patch --attach master..mybranch --stdout <span class="p">|</span> git imap-send
</pre></div>
</div>
<p>Then, your .git/config should have [imap] sections.</p>
<div class="highlight-ini"><div class="highlight"><pre><span class="k">[imap]</span>
      <span class="na">host</span> <span class="o">=</span> <span class="s">imaps://imap.gmail.com</span>
<span class="s">      user = your.gmail.account@gmail.com</span>
<span class="s">      pass = himitsu!</span>
<span class="s">      port = 993</span>
<span class="s">      sslverify = false</span>
<span class="c1">; in English</span>
      <span class="na">folder</span> <span class="o">=</span> <span class="s">&quot;[Gmail]/Drafts&quot;</span>
<span class="c1">; example for Japanese, &quot;Modified UTF-7&quot; encoded.</span>
      <span class="na">folder</span> <span class="o">=</span> <span class="s">&quot;[Gmail]/&amp;Tgtm+DBN-&quot;</span>
<span class="c1">; example for Traditional Chinese</span>
      <span class="na">folder</span> <span class="o">=</span> <span class="s">&quot;[Gmail]/&amp;g0l6Pw-&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="for-developers-to-work-with-git-svn">
<h4><a class="toc-backref" href="#id21">For developers to work with git-svn</a><a class="headerlink" href="#for-developers-to-work-with-git-svn" title="Permalink to this headline">¶</a></h4>
<p>To set up clone from which you can submit code using <code class="docutils literal"><span class="pre">git-svn</span></code>, run:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git clone http://llvm.org/git/llvm.git
<span class="gp">%</span> <span class="nb">cd </span>llvm
<span class="gp">%</span> git svn init https://llvm.org/svn/llvm-project/llvm/trunk --username<span class="o">=</span>&lt;username&gt;
<span class="gp">%</span> git config svn-remote.svn.fetch :refs/remotes/origin/master
<span class="gp">%</span> git svn rebase -l  <span class="c"># -l avoids fetching ahead of the git mirror.</span>

<span class="gp">#</span> If you have clang too:
<span class="gp">%</span> <span class="nb">cd </span>tools
<span class="gp">%</span> git clone http://llvm.org/git/clang.git
<span class="gp">%</span> <span class="nb">cd </span>clang
<span class="gp">%</span> git svn init https://llvm.org/svn/llvm-project/cfe/trunk --username<span class="o">=</span>&lt;username&gt;
<span class="gp">%</span> git config svn-remote.svn.fetch :refs/remotes/origin/master
<span class="gp">%</span> git svn rebase -l
</pre></div>
</div>
<p>Likewise for compiler-rt and test-suite.</p>
<p>To update this clone without generating git-svn tags that conflict with the
upstream Git repo, run:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git fetch <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="nb">cd </span>tools/clang <span class="o">&amp;&amp;</span> git fetch<span class="o">)</span>  <span class="c"># Get matching revisions of both trees.</span>
<span class="gp">%</span> git checkout master
<span class="gp">%</span> git svn rebase -l
<span class="gp">%</span> <span class="o">(</span><span class="nb">cd </span>tools/clang <span class="o">&amp;&amp;</span>
<span class="go">   git checkout master &amp;&amp;</span>
<span class="go">   git svn rebase -l)</span>
</pre></div>
</div>
<p>Likewise for compiler-rt and test-suite.</p>
<p>This leaves your working directories on their master branches, so you&#8217;ll need to
<code class="docutils literal"><span class="pre">checkout</span></code> each working branch individually and <code class="docutils literal"><span class="pre">rebase</span></code> it on top of its
parent branch.</p>
<p>For those who wish to be able to update an llvm repo/revert patches easily using
git-svn, please look in the directory for the scripts <code class="docutils literal"><span class="pre">git-svnup</span></code> and
<code class="docutils literal"><span class="pre">git-svnrevert</span></code>.</p>
<p>To perform the aforementioned update steps go into your source directory and
just type <code class="docutils literal"><span class="pre">git-svnup</span></code> or <code class="docutils literal"><span class="pre">git</span> <span class="pre">svnup</span></code> and everything will just work.</p>
<p>If one wishes to revert a commit with git-svn, but do not want the git hash to
escape into the commit message, one can use the script <code class="docutils literal"><span class="pre">git-svnrevert</span></code> or
<code class="docutils literal"><span class="pre">git</span> <span class="pre">svnrevert</span></code> which will take in the git hash for the commit you want to
revert, look up the appropriate svn revision, and output a message where all
references to the git hash have been replaced with the svn revision.</p>
<p>To commit back changes via git-svn, use <code class="docutils literal"><span class="pre">git</span> <span class="pre">svn</span> <span class="pre">dcommit</span></code>:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> git svn dcommit
</pre></div>
</div>
<p>Note that git-svn will create one SVN commit for each Git commit you have pending,
so squash and edit each commit before executing <code class="docutils literal"><span class="pre">dcommit</span></code> to make sure they all
conform to the coding standards and the developers&#8217; policy.</p>
<p>On success, <code class="docutils literal"><span class="pre">dcommit</span></code> will rebase against the HEAD of SVN, so to avoid conflict,
please make sure your current branch is up-to-date (via fetch/rebase) before
proceeding.</p>
<p>The git-svn metadata can get out of sync after you mess around with branches and
<code class="docutils literal"><span class="pre">dcommit</span></code>. When that happens, <code class="docutils literal"><span class="pre">git</span> <span class="pre">svn</span> <span class="pre">dcommit</span></code> stops working, complaining
about files with uncommitted changes. The fix is to rebuild the metadata:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> rm -rf .git/svn
<span class="gp">%</span> git svn rebase -l
</pre></div>
</div>
<p>Please, refer to the Git-SVN manual (<code class="docutils literal"><span class="pre">man</span> <span class="pre">git-svn</span></code>) for more information.</p>
</div>
</div>
<div class="section" id="local-llvm-configuration">
<h3><a class="toc-backref" href="#id22">Local LLVM Configuration</a><a class="headerlink" href="#local-llvm-configuration" title="Permalink to this headline">¶</a></h3>
<p>Once checked out from the Subversion repository, the LLVM suite source code must
be configured before being built. For instructions using autotools please see
<a class="reference external" href="BuildingLLVMWithAutotools.html">Building LLVM With Autotools</a>. The
recommended process uses CMake. Unlinke the normal <code class="docutils literal"><span class="pre">configure</span></code> script, CMake
generates the build files in whatever format you request as well as various
<code class="docutils literal"><span class="pre">*.inc</span></code> files, and <code class="docutils literal"><span class="pre">llvm/include/Config/config.h</span></code>.</p>
<p>Variables are passed to <code class="docutils literal"><span class="pre">cmake</span></code> on the command line using the format
<code class="docutils literal"><span class="pre">-D&lt;variable</span> <span class="pre">name&gt;=&lt;value&gt;</span></code>. The following variables are some common options
used by people developing LLVM.</p>
<table border="1" class="docutils">
<colgroup>
<col width="32%" />
<col width="68%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Variable</th>
<th class="head">Purpose</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>CMAKE_C_COMPILER</td>
<td>Tells <code class="docutils literal"><span class="pre">cmake</span></code> which C compiler to use. By
default, this will be /usr/bin/cc.</td>
</tr>
<tr class="row-odd"><td>CMAKE_CXX_COMPILER</td>
<td>Tells <code class="docutils literal"><span class="pre">cmake</span></code> which C++ compiler to use. By
default, this will be /usr/bin/c++.</td>
</tr>
<tr class="row-even"><td>CMAKE_BUILD_TYPE</td>
<td>Tells <code class="docutils literal"><span class="pre">cmake</span></code> what type of build you are trying
to generate files for. Valid options are Debug,
Release, RelWithDebInfo, and MinSizeRel. Default
is Debug.</td>
</tr>
<tr class="row-odd"><td>CMAKE_INSTALL_PREFIX</td>
<td>Specifies the install directory to target when
running the install action of the build files.</td>
</tr>
<tr class="row-even"><td>LLVM_TARGETS_TO_BUILD</td>
<td>A semicolon delimited list controlling which
targets will be built and linked into llc. This is
equivalent to the <code class="docutils literal"><span class="pre">--enable-targets</span></code> option in
the configure script. The default list is defined
as <code class="docutils literal"><span class="pre">LLVM_ALL_TARGETS</span></code>, and can be set to include
out-of-tree targets. The default value includes:
<code class="docutils literal"><span class="pre">AArch64,</span> <span class="pre">AMDGPU,</span> <span class="pre">ARM,</span> <span class="pre">BPF,</span> <span class="pre">CppBackend,</span> <span class="pre">Hexagon,</span>
<span class="pre">Mips,</span> <span class="pre">MSP430,</span> <span class="pre">NVPTX,</span> <span class="pre">PowerPC,</span> <span class="pre">Sparc,</span> <span class="pre">SystemZ</span>
<span class="pre">X86,</span> <span class="pre">XCore</span></code>.</td>
</tr>
<tr class="row-odd"><td>LLVM_ENABLE_DOXYGEN</td>
<td>Build doxygen-based documentation from the source
code This is disabled by default because it is
slow and generates a lot of output.</td>
</tr>
<tr class="row-even"><td>LLVM_ENABLE_SPHINX</td>
<td>Build sphinx-based documentation from the source
code. This is disabled by default because it is
slow and generates a lot of output.</td>
</tr>
<tr class="row-odd"><td>LLVM_BUILD_LLVM_DYLIB</td>
<td>Generate libLLVM.so. This library contains a
default set of LLVM components that can be
overridden with <code class="docutils literal"><span class="pre">LLVM_DYLIB_COMPONENTS</span></code>. The
default contains most of LLVM and is defined in
<code class="docutils literal"><span class="pre">tools/llvm-shlib/CMakelists.txt</span></code>.</td>
</tr>
<tr class="row-even"><td>LLVM_OPTIMIZED_TABLEGEN</td>
<td>Builds a release tablegen that gets used during
the LLVM build. This can dramatically speed up
debug builds.</td>
</tr>
</tbody>
</table>
<p>To configure LLVM, follow these steps:</p>
<ol class="arabic">
<li><p class="first">Change directory into the object root directory:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>OBJ_ROOT
</pre></div>
</div>
</li>
<li><p class="first">Run the <code class="docutils literal"><span class="pre">cmake</span></code>:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> cmake -G <span class="s2">&quot;Unix Makefiles&quot;</span> -DCMAKE_INSTALL_PREFIX<span class="o">=</span><span class="nv">prefix</span><span class="o">=</span>/install/path
<span class="go">  [other options] SRC_ROOT</span>
</pre></div>
</div>
</li>
</ol>
</div>
<div class="section" id="compiling-the-llvm-suite-source-code">
<h3><a class="toc-backref" href="#id23">Compiling the LLVM Suite Source Code</a><a class="headerlink" href="#compiling-the-llvm-suite-source-code" title="Permalink to this headline">¶</a></h3>
<p>Unlike with autotools, with CMake your build type is defined at configuration.
If you want to change your build type, you can re-run cmake with the following
invocation:</p>
<blockquote>
<div><div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> cmake -G <span class="s2">&quot;Unix Makefiles&quot;</span> -DCMAKE_BUILD_TYPE<span class="o">=</span><span class="nb">type </span>SRC_ROOT
</pre></div>
</div>
</div></blockquote>
<p>Between runs, CMake preserves the values set for all options. CMake has the
following build types defined:</p>
<p>Debug</p>
<blockquote>
<div>These builds are the default. The build system will compile the tools and
libraries unoptimized, with debugging information, and asserts enabled.</div></blockquote>
<p>Release</p>
<blockquote>
<div>For these builds, the build system will compile the tools and libraries
with optimizations enabled and not generate debug info. CMakes default
optimization level is -O3. This can be configured by setting the
<code class="docutils literal"><span class="pre">CMAKE_CXX_FLAGS_RELEASE</span></code> variable on the CMake command line.</div></blockquote>
<p>RelWithDebInfo</p>
<blockquote>
<div>These builds are useful when debugging. They generate optimized binaries with
debug information. CMakes default optimization level is -O2. This can be
configured by setting the <code class="docutils literal"><span class="pre">CMAKE_CXX_FLAGS_RELWITHDEBINFO</span></code> variable on the
CMake command line.</div></blockquote>
<p>Once you have LLVM configured, you can build it by entering the <em>OBJ_ROOT</em>
directory and issuing the following command:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> make
</pre></div>
</div>
<p>If the build fails, please <a class="reference internal" href="#check-here">check here</a> to see if you are using a version of
GCC that is known not to compile LLVM.</p>
<p>If you have multiple processors in your machine, you may wish to use some of the
parallel build options provided by GNU Make.  For example, you could use the
command:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> make -j2
</pre></div>
</div>
<p>There are several special targets which are useful when working with the LLVM
source code:</p>
<p><code class="docutils literal"><span class="pre">make</span> <span class="pre">clean</span></code></p>
<blockquote>
<div>Removes all files generated by the build.  This includes object files,
generated C/C++ files, libraries, and executables.</div></blockquote>
<p><code class="docutils literal"><span class="pre">make</span> <span class="pre">install</span></code></p>
<blockquote>
<div>Installs LLVM header files, libraries, tools, and documentation in a hierarchy
under <code class="docutils literal"><span class="pre">$PREFIX</span></code>, specified with <code class="docutils literal"><span class="pre">CMAKE_INSTALL_PREFIX</span></code>, which
defaults to <code class="docutils literal"><span class="pre">/usr/local</span></code>.</div></blockquote>
<p><code class="docutils literal"><span class="pre">make</span> <span class="pre">docs-llvm-html</span></code></p>
<blockquote>
<div>If configured with <code class="docutils literal"><span class="pre">-DLLVM_ENABLE_SPHINX=On</span></code>, this will generate a directory
at <code class="docutils literal"><span class="pre">OBJ_ROOT/docs/html</span></code> which contains the HTML formatted documentation.</div></blockquote>
</div>
<div class="section" id="cross-compiling-llvm">
<h3><a class="toc-backref" href="#id24">Cross-Compiling LLVM</a><a class="headerlink" href="#cross-compiling-llvm" title="Permalink to this headline">¶</a></h3>
<p>It is possible to cross-compile LLVM itself. That is, you can create LLVM
executables and libraries to be hosted on a platform different from the platform
where they are built (a Canadian Cross build). To generate build files for
cross-compiling CMake provides a variable <code class="docutils literal"><span class="pre">CMAKE_TOOLCHAIN_FILE</span></code> which can
define compiler flags and variables used during the CMake test operations.</p>
<p>The result of such a build is executables that are not runnable on on the build
host but can be executed on the target. As an example the following CMake
invocation can generate build files targeting iOS. This will work on Mac OS X
with the latest Xcode:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> cmake -G <span class="s2">&quot;Ninja&quot;</span> -DCMAKE_OSX_ARCHITECTURES<span class="o">=</span>“armv7<span class="p">;</span>armv7s<span class="p">;</span>arm64<span class="s2">&quot;</span>
<span class="go">  -DCMAKE_TOOLCHAIN_FILE=&lt;PATH_TO_LLVM&gt;/cmake/platforms/iOS.cmake</span>
<span class="go">  -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_RUNTIME=Off -DLLVM_INCLUDE_TESTS=Off</span>
<span class="go">  -DLLVM_INCLUDE_EXAMPLES=Off -DLLVM_ENABLE_BACKTRACES=Off [options]</span>
<span class="go">  &lt;PATH_TO_LLVM&gt;</span>
</pre></div>
</div>
<p>Note: There are some additional flags that need to be passed when building for
iOS due to limitations in the iOS SDK.</p>
<p>Check <a class="reference internal" href="HowToCrossCompileLLVM.html"><em>How To Cross-Compile Clang/LLVM using Clang/LLVM</em></a> and <a class="reference external" href="http://clang.llvm.org/docs/CrossCompilation.html">Clang docs on how to cross-compile in general</a> for more information
about cross-compiling.</p>
</div>
<div class="section" id="the-location-of-llvm-object-files">
<h3><a class="toc-backref" href="#id25">The Location of LLVM Object Files</a><a class="headerlink" href="#the-location-of-llvm-object-files" title="Permalink to this headline">¶</a></h3>
<p>The LLVM build system is capable of sharing a single LLVM source tree among
several LLVM builds.  Hence, it is possible to build LLVM for several different
platforms or configurations using the same source tree.</p>
<p>This is accomplished in the typical autoconf manner:</p>
<ul>
<li><p class="first">Change directory to where the LLVM object files should live:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>OBJ_ROOT
</pre></div>
</div>
</li>
<li><p class="first">Run <code class="docutils literal"><span class="pre">cmake</span></code>:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> cmake -G <span class="s2">&quot;Unix Makefiles&quot;</span> SRC_ROOT
</pre></div>
</div>
</li>
</ul>
<p>The LLVM build will create a structure underneath <em>OBJ_ROOT</em> that matches the
LLVM source tree. At each level where source files are present in the source
tree there will be a corresponding <code class="docutils literal"><span class="pre">CMakeFiles</span></code> directory in the <em>OBJ_ROOT</em>.
Underneath that directory there is another directory with a name ending in
<code class="docutils literal"><span class="pre">.dir</span></code> under which you&#8217;ll find object files for each source.</p>
<p>For example:</p>
<blockquote>
<div><div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>llvm_build_dir
<span class="gp">%</span> find lib/Support/ -name APFloat*
<span class="go">lib/Support/CMakeFiles/LLVMSupport.dir/APFloat.cpp.o</span>
</pre></div>
</div>
</div></blockquote>
</div>
<div class="section" id="optional-configuration-items">
<h3><a class="toc-backref" href="#id26">Optional Configuration Items</a><a class="headerlink" href="#optional-configuration-items" title="Permalink to this headline">¶</a></h3>
<p>If you&#8217;re running on a Linux system that supports the <a class="reference external" href="http://en.wikipedia.org/wiki/binfmt_misc">binfmt_misc</a>
module, and you have root access on the system, you can set your system up to
execute LLVM bitcode files directly. To do this, use commands like this (the
first command may not be required if you are already using the module):</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
<span class="gp">%</span> <span class="nb">echo</span> <span class="s1">&#39;:llvm:M::BC::/path/to/lli:&#39;</span> &gt; /proc/sys/fs/binfmt_misc/register
<span class="gp">%</span> chmod u+x hello.bc   <span class="o">(</span><span class="k">if</span> needed<span class="o">)</span>
<span class="gp">%</span> ./hello.bc
</pre></div>
</div>
<p>This allows you to execute LLVM bitcode files directly.  On Debian, you can also
use this command instead of the &#8216;echo&#8217; command above:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> sudo update-binfmts --install llvm /path/to/lli --magic <span class="s1">&#39;BC&#39;</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="general-layout">
<span id="program-layout"></span><span id="id5"></span><h2><a class="toc-backref" href="#id27">Program Layout</a><a class="headerlink" href="#general-layout" title="Permalink to this headline">¶</a></h2>
<p>One useful source of information about the LLVM source base is the LLVM <a class="reference external" href="http://www.doxygen.org/">doxygen</a> documentation available at
<a class="reference external" href="http://llvm.org/doxygen/">http://llvm.org/doxygen/</a>.  The following is a brief introduction to code
layout:</p>
<div class="section" id="llvm-examples">
<h3><a class="toc-backref" href="#id28"><code class="docutils literal"><span class="pre">llvm/examples</span></code></a><a class="headerlink" href="#llvm-examples" title="Permalink to this headline">¶</a></h3>
<p>This directory contains some simple examples of how to use the LLVM IR and JIT.</p>
</div>
<div class="section" id="llvm-include">
<h3><a class="toc-backref" href="#id29"><code class="docutils literal"><span class="pre">llvm/include</span></code></a><a class="headerlink" href="#llvm-include" title="Permalink to this headline">¶</a></h3>
<p>This directory contains public header files exported from the LLVM library. The
three main subdirectories of this directory are:</p>
<p><code class="docutils literal"><span class="pre">llvm/include/llvm</span></code></p>
<blockquote>
<div>This directory contains all of the LLVM specific header files.  This directory
also has subdirectories for different portions of LLVM: <code class="docutils literal"><span class="pre">Analysis</span></code>,
<code class="docutils literal"><span class="pre">CodeGen</span></code>, <code class="docutils literal"><span class="pre">Target</span></code>, <code class="docutils literal"><span class="pre">Transforms</span></code>, etc...</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/include/llvm/Support</span></code></p>
<blockquote>
<div>This directory contains generic support libraries that are provided with LLVM
but not necessarily specific to LLVM. For example, some C++ STL utilities and
a Command Line option processing library store their header files here.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/include/llvm/Config</span></code></p>
<blockquote>
<div>This directory contains header files configured by the <code class="docutils literal"><span class="pre">configure</span></code> script.
They wrap &#8220;standard&#8221; UNIX and C header files.  Source code can include these
header files which automatically take care of the conditional #includes that
the <code class="docutils literal"><span class="pre">configure</span></code> script generates.</div></blockquote>
</div>
<div class="section" id="llvm-lib">
<h3><a class="toc-backref" href="#id30"><code class="docutils literal"><span class="pre">llvm/lib</span></code></a><a class="headerlink" href="#llvm-lib" title="Permalink to this headline">¶</a></h3>
<p>This directory contains most of the source files of the LLVM system. In LLVM,
almost all code exists in libraries, making it very easy to share code among the
different <a class="reference internal" href="#tools">tools</a>.</p>
<p><code class="docutils literal"><span class="pre">llvm/lib/IR/</span></code></p>
<blockquote>
<div>This directory holds the core LLVM source files that implement core classes
like Instruction and BasicBlock.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/AsmParser/</span></code></p>
<blockquote>
<div>This directory holds the source code for the LLVM assembly language parser
library.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/Bitcode/</span></code></p>
<blockquote>
<div>This directory holds code for reading and write LLVM bitcode.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/Analysis/</span></code></p>
<blockquote>
<div>This directory contains a variety of different program analyses, such as
Dominator Information, Call Graphs, Induction Variables, Interval
Identification, Natural Loop Identification, etc.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/Transforms/</span></code></p>
<blockquote>
<div>This directory contains the source code for the LLVM to LLVM program
transformations, such as Aggressive Dead Code Elimination, Sparse Conditional
Constant Propagation, Inlining, Loop Invariant Code Motion, Dead Global
Elimination, and many others.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/Target/</span></code></p>
<blockquote>
<div>This directory contains files that describe various target architectures for
code generation.  For example, the <code class="docutils literal"><span class="pre">llvm/lib/Target/X86</span></code> directory holds the
X86 machine description while <code class="docutils literal"><span class="pre">llvm/lib/Target/ARM</span></code> implements the ARM
backend.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/CodeGen/</span></code></p>
<blockquote>
<div>This directory contains the major parts of the code generator: Instruction
Selector, Instruction Scheduling, and Register Allocation.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/MC/</span></code></p>
<blockquote>
<div>(FIXME: T.B.D.)</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/Debugger/</span></code></p>
<blockquote>
<div>This directory contains the source level debugger library that makes it
possible to instrument LLVM programs so that a debugger could identify source
code locations at which the program is executing.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/ExecutionEngine/</span></code></p>
<blockquote>
<div>This directory contains libraries for executing LLVM bitcode directly at
runtime in both interpreted and JIT compiled fashions.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm/lib/Support/</span></code></p>
<blockquote>
<div>This directory contains the source code that corresponds to the header files
located in <code class="docutils literal"><span class="pre">llvm/include/ADT/</span></code> and <code class="docutils literal"><span class="pre">llvm/include/Support/</span></code>.</div></blockquote>
</div>
<div class="section" id="llvm-projects">
<h3><a class="toc-backref" href="#id31"><code class="docutils literal"><span class="pre">llvm/projects</span></code></a><a class="headerlink" href="#llvm-projects" title="Permalink to this headline">¶</a></h3>
<p>This directory contains projects that are not strictly part of LLVM but are
shipped with LLVM. This is also the directory where you should create your own
LLVM-based projects.</p>
</div>
<div class="section" id="llvm-runtime">
<h3><a class="toc-backref" href="#id32"><code class="docutils literal"><span class="pre">llvm/runtime</span></code></a><a class="headerlink" href="#llvm-runtime" title="Permalink to this headline">¶</a></h3>
<p>This directory contains libraries which are compiled into LLVM bitcode and used
when linking programs with the Clang front end.  Most of these libraries are
skeleton versions of real libraries; for example, libc is a stripped down
version of glibc.</p>
<p>Unlike the rest of the LLVM suite, this directory needs the LLVM GCC front end
to compile.</p>
</div>
<div class="section" id="llvm-test">
<h3><a class="toc-backref" href="#id33"><code class="docutils literal"><span class="pre">llvm/test</span></code></a><a class="headerlink" href="#llvm-test" title="Permalink to this headline">¶</a></h3>
<p>This directory contains feature and regression tests and other basic sanity
checks on the LLVM infrastructure. These are intended to run quickly and cover a
lot of territory without being exhaustive.</p>
</div>
<div class="section" id="test-suite">
<h3><a class="toc-backref" href="#id34"><code class="docutils literal"><span class="pre">test-suite</span></code></a><a class="headerlink" href="#test-suite" title="Permalink to this headline">¶</a></h3>
<p>This is not a directory in the normal llvm module; it is a separate Subversion
module that must be checked out (usually to <code class="docutils literal"><span class="pre">projects/test-suite</span></code>).  This
module contains a comprehensive correctness, performance, and benchmarking test
suite for LLVM. It is a separate Subversion module because not every LLVM user
is interested in downloading or building such a comprehensive test suite. For
further details on this test suite, please see the <a class="reference internal" href="TestingGuide.html"><em>Testing Guide</em></a> document.</p>
</div>
<div class="section" id="llvm-tools">
<span id="tools"></span><h3><a class="toc-backref" href="#id35"><code class="docutils literal"><span class="pre">llvm/tools</span></code></a><a class="headerlink" href="#llvm-tools" title="Permalink to this headline">¶</a></h3>
<p>The <strong>tools</strong> directory contains the executables built out of the libraries
above, which form the main part of the user interface.  You can always get help
for a tool by typing <code class="docutils literal"><span class="pre">tool_name</span> <span class="pre">-help</span></code>.  The following is a brief introduction
to the most important tools.  More detailed information is in
the <a class="reference external" href="CommandGuide/index.html">Command Guide</a>.</p>
<p><code class="docutils literal"><span class="pre">bugpoint</span></code></p>
<blockquote>
<div><code class="docutils literal"><span class="pre">bugpoint</span></code> is used to debug optimization passes or code generation backends
by narrowing down the given test case to the minimum number of passes and/or
instructions that still cause a problem, whether it is a crash or
miscompilation. See <a class="reference external" href="HowToSubmitABug.html">HowToSubmitABug.html</a> for more information on using
<code class="docutils literal"><span class="pre">bugpoint</span></code>.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm-ar</span></code></p>
<blockquote>
<div>The archiver produces an archive containing the given LLVM bitcode files,
optionally with an index for faster lookup.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm-as</span></code></p>
<blockquote>
<div>The assembler transforms the human readable LLVM assembly to LLVM bitcode.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm-dis</span></code></p>
<blockquote>
<div>The disassembler transforms the LLVM bitcode to human readable LLVM assembly.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvm-link</span></code></p>
<blockquote>
<div><code class="docutils literal"><span class="pre">llvm-link</span></code>, not surprisingly, links multiple LLVM modules into a single
program.</div></blockquote>
<p><code class="docutils literal"><span class="pre">lli</span></code></p>
<blockquote>
<div><code class="docutils literal"><span class="pre">lli</span></code> is the LLVM interpreter, which can directly execute LLVM bitcode
(although very slowly...). For architectures that support it (currently x86,
Sparc, and PowerPC), by default, <code class="docutils literal"><span class="pre">lli</span></code> will function as a Just-In-Time
compiler (if the functionality was compiled in), and will execute the code
<em>much</em> faster than the interpreter.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llc</span></code></p>
<blockquote>
<div><code class="docutils literal"><span class="pre">llc</span></code> is the LLVM backend compiler, which translates LLVM bitcode to a
native code assembly file or to C code (with the <code class="docutils literal"><span class="pre">-march=c</span></code> option).</div></blockquote>
<p><code class="docutils literal"><span class="pre">opt</span></code></p>
<blockquote>
<div><p><code class="docutils literal"><span class="pre">opt</span></code> reads LLVM bitcode, applies a series of LLVM to LLVM transformations
(which are specified on the command line), and then outputs the resultant
bitcode.  The &#8216;<code class="docutils literal"><span class="pre">opt</span> <span class="pre">-help</span></code>&#8216; command is a good way to get a list of the
program transformations available in LLVM.</p>
<p><code class="docutils literal"><span class="pre">opt</span></code> can also be used to run a specific analysis on an input LLVM bitcode
file and print out the results.  It is primarily useful for debugging
analyses, or familiarizing yourself with what an analysis does.</p>
</div></blockquote>
</div>
<div class="section" id="llvm-utils">
<h3><a class="toc-backref" href="#id36"><code class="docutils literal"><span class="pre">llvm/utils</span></code></a><a class="headerlink" href="#llvm-utils" title="Permalink to this headline">¶</a></h3>
<p>This directory contains utilities for working with LLVM source code, and some of
the utilities are actually required as part of the build process because they
are code generators for parts of LLVM infrastructure.</p>
<p><code class="docutils literal"><span class="pre">codegen-diff</span></code></p>
<blockquote>
<div><code class="docutils literal"><span class="pre">codegen-diff</span></code> is a script that finds differences between code that LLC
generates and code that LLI generates. This is a useful tool if you are
debugging one of them, assuming that the other generates correct output. For
the full user manual, run <code class="docutils literal"><span class="pre">`perldoc</span> <span class="pre">codegen-diff'</span></code>.</div></blockquote>
<p><code class="docutils literal"><span class="pre">emacs/</span></code></p>
<blockquote>
<div>The <code class="docutils literal"><span class="pre">emacs</span></code> directory contains syntax-highlighting files which will work
with Emacs and XEmacs editors, providing syntax highlighting support for LLVM
assembly files and TableGen description files. For information on how to use
the syntax files, consult the <code class="docutils literal"><span class="pre">README</span></code> file in that directory.</div></blockquote>
<p><code class="docutils literal"><span class="pre">getsrcs.sh</span></code></p>
<blockquote>
<div>The <code class="docutils literal"><span class="pre">getsrcs.sh</span></code> script finds and outputs all non-generated source files,
which is useful if one wishes to do a lot of development across directories
and does not want to individually find each file. One way to use it is to run,
for example: <code class="docutils literal"><span class="pre">xemacs</span> <span class="pre">`utils/getsources.sh`</span></code> from the top of your LLVM source
tree.</div></blockquote>
<p><code class="docutils literal"><span class="pre">llvmgrep</span></code></p>
<blockquote>
<div>This little tool performs an <code class="docutils literal"><span class="pre">egrep</span> <span class="pre">-H</span> <span class="pre">-n</span></code> on each source file in LLVM and
passes to it a regular expression provided on <code class="docutils literal"><span class="pre">llvmgrep</span></code>&#8216;s command
line. This is a very efficient way of searching the source base for a
particular regular expression.</div></blockquote>
<p><code class="docutils literal"><span class="pre">makellvm</span></code></p>
<blockquote>
<div>The <code class="docutils literal"><span class="pre">makellvm</span></code> script compiles all files in the current directory and then
compiles and links the tool that is the first argument. For example, assuming
you are in the directory <code class="docutils literal"><span class="pre">llvm/lib/Target/Sparc</span></code>, if <code class="docutils literal"><span class="pre">makellvm</span></code> is in your
path, simply running <code class="docutils literal"><span class="pre">makellvm</span> <span class="pre">llc</span></code> will make a build of the current
directory, switch to directory <code class="docutils literal"><span class="pre">llvm/tools/llc</span></code> and build it, causing a
re-linking of LLC.</div></blockquote>
<p><code class="docutils literal"><span class="pre">TableGen/</span></code></p>
<blockquote>
<div>The <code class="docutils literal"><span class="pre">TableGen</span></code> directory contains the tool used to generate register
descriptions, instruction set descriptions, and even assemblers from common
TableGen description files.</div></blockquote>
<p><code class="docutils literal"><span class="pre">vim/</span></code></p>
<blockquote>
<div>The <code class="docutils literal"><span class="pre">vim</span></code> directory contains syntax-highlighting files which will work with
the VIM editor, providing syntax highlighting support for LLVM assembly files
and TableGen description files. For information on how to use the syntax
files, consult the <code class="docutils literal"><span class="pre">README</span></code> file in that directory.</div></blockquote>
</div>
</div>
<div class="section" id="an-example-using-the-llvm-tool-chain">
<span id="simple-example"></span><h2><a class="toc-backref" href="#id37">An Example Using the LLVM Tool Chain</a><a class="headerlink" href="#an-example-using-the-llvm-tool-chain" title="Permalink to this headline">¶</a></h2>
<p>This section gives an example of using LLVM with the Clang front end.</p>
<div class="section" id="example-with-clang">
<h3><a class="toc-backref" href="#id38">Example with clang</a><a class="headerlink" href="#example-with-clang" title="Permalink to this headline">¶</a></h3>
<ol class="arabic">
<li><p class="first">First, create a simple C file, name it &#8216;hello.c&#8217;:</p>
<div class="highlight-c"><div class="highlight"><pre><span class="cp">#include &lt;stdio.h&gt;</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="n">printf</span><span class="p">(</span><span class="s">&quot;hello world</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
  <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
</li>
<li><p class="first">Next, compile the C file into a native executable:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> clang hello.c -o hello
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Clang works just like GCC by default.  The standard -S and -c arguments
work as usual (producing a native .s or .o file, respectively).</p>
</div>
</li>
<li><p class="first">Next, compile the C file into an LLVM bitcode file:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> clang -O3 -emit-llvm hello.c -c -o hello.bc
</pre></div>
</div>
<p>The -emit-llvm option can be used with the -S or -c options to emit an LLVM
<code class="docutils literal"><span class="pre">.ll</span></code> or <code class="docutils literal"><span class="pre">.bc</span></code> file (respectively) for the code.  This allows you to use
the <a class="reference external" href="CommandGuide/index.html">standard LLVM tools</a> on the bitcode file.</p>
</li>
<li><p class="first">Run the program in both forms. To run the program, use:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> ./hello
</pre></div>
</div>
<p>and</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> lli hello.bc
</pre></div>
</div>
<p>The second examples shows how to invoke the LLVM JIT, <a class="reference internal" href="CommandGuide/lli.html"><em>lli</em></a>.</p>
</li>
<li><p class="first">Use the <code class="docutils literal"><span class="pre">llvm-dis</span></code> utility to take a look at the LLVM assembly code:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> llvm-dis &lt; hello.bc <span class="p">|</span> less
</pre></div>
</div>
</li>
<li><p class="first">Compile the program to native assembly using the LLC code generator:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> llc hello.bc -o hello.s
</pre></div>
</div>
</li>
<li><p class="first">Assemble the native assembly language file into a program:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> /opt/SUNWspro/bin/cc -xarch<span class="o">=</span>v9 hello.s -o hello.native   <span class="c"># On Solaris</span>

<span class="gp">%</span> gcc hello.s -o hello.native                              <span class="c"># On others</span>
</pre></div>
</div>
</li>
<li><p class="first">Execute the native code program:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> ./hello.native
</pre></div>
</div>
<p>Note that using clang to compile directly to native code (i.e. when the
<code class="docutils literal"><span class="pre">-emit-llvm</span></code> option is not present) does steps 6/7/8 for you.</p>
</li>
</ol>
</div>
</div>
<div class="section" id="common-problems">
<h2><a class="toc-backref" href="#id39">Common Problems</a><a class="headerlink" href="#common-problems" title="Permalink to this headline">¶</a></h2>
<p>If you are having problems building or using LLVM, or if you have any other
general questions about LLVM, please consult the <a class="reference external" href="FAQ.html">Frequently Asked
Questions</a> page.</p>
</div>
<div class="section" id="links">
<span id="id6"></span><h2><a class="toc-backref" href="#id40">Links</a><a class="headerlink" href="#links" title="Permalink to this headline">¶</a></h2>
<p>This document is just an <strong>introduction</strong> on how to use LLVM to do some simple
things... there are many more interesting and complicated things that you can do
that aren&#8217;t documented here (but we&#8217;ll gladly accept a patch if you want to
write something up!).  For more information about LLVM, check out:</p>
<ul class="simple">
<li><a class="reference external" href="http://llvm.org/">LLVM Homepage</a></li>
<li><a class="reference external" href="http://llvm.org/doxygen/">LLVM Doxygen Tree</a></li>
<li><a class="reference external" href="http://llvm.org/docs/Projects.html">Starting a Project that Uses LLVM</a></li>
</ul>
</div>
</div>


          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="GettingStartedVS.html" title="Getting Started with the LLVM System using Microsoft Visual Studio"
             >next</a> |</li>
        <li class="right" >
          <a href="CommandGuide/llvm-readobj.html" title="llvm-readobj - LLVM Object Reader"
             >previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>
 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2003-2015, LLVM Project.
      Last updated on 2015-09-08.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
    </div>
  </body>
</html>